﻿/*  
 *  IIS LogFile Analyser, Copyright (C) 2013. http://www.iis-analyser.com
 *  --
 *  This program is free software, provided "AS IS" WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
 * 
 *  File Author: Ian Quigley,    2013-02-23
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Text;

namespace Web.DisplayView
{
    public class DisplayGridView : IDisplayView
    {
        public DisplayGridView()
        {}

        public string Name()
        {
            return "Simple Grid View";
        }

        public string ToHtml(DataSet dataset)
        {
            StringBuilder html = new StringBuilder();

            html.Append( "<table cellspacing='0'><tr><thead>" );

            foreach (DataColumn column in dataset.Tables[0].Columns)
            {
                html.AppendFormat( "<td>{0}</td>", column.Caption );
            }
            html.Append( "</thead></tr>" );

            foreach (DataRow row in dataset.Tables[0].Rows)
            {
                html.Append( "<tr>" );
                for (int i = 0; i < dataset.Tables[0].Columns.Count; i++)
                    html.AppendFormat( "<td>{0}</td>", row[i] );

                html.Append( "</tr>" );
            }

            html.Append( "</table>" );
            return html.ToString();
        }
    }
}